<template>
  <div class="shopcart-wrapper" :class="{chang:valueChange}">
    <div class="shopcart">
      <div class="myfoodlist" v-show="this.shopCart.length">
        <div class="cart-title border">
          <h2>购物车</h2>
          <div class="clear" @click="cleanCart">清空</div>
        </div>
        <ul class="eachfood-list" ref="eachFoodList">
          <li class="eachfood border" v-for="item in shopCart">
            <span class="food-name">{{item.name}}</span>
            <span class="food-price"><span class="yen">&yen;</span>{{item.price}}</span>
            <div class="ctrl">
              <Cartcontrol :obj="item" class="button"></Cartcontrol>
            </div>
          </li>
        </ul>
      </div>
      <div class="footer-content">
        <div class="content-left" ref="contentLeftHook">
          <div class="logo-warper">
            <div class="logo" v-if="this.total<=0"><i class="icon-shopping_cart"></i></div>
            <div class="logo highlight" v-if="this.total>0"><i class="icon-shopping_cart"></i></div>
            <div class="num" v-show="this.unmber>0">{{unmber}}</div>
          </div>
          <div class="price">{{total}}¥</div>
          <div class="desc">另需配送费¥4元</div>
        </div>
        <div class="content-right" ref="need">
          <div class="pay" v-if="this.needmoney>0">还差{{needmoney}}¥起送</div>
          <div class="pay enough" v-if="this.needmoney<=0">立即购买</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
  import {mapGetters, mapActions} from "vuex"
  import Cartcontrol from "../cartcontrol/Cartcontrol.vue"
  import IScroll from 'iscroll/build/iscroll-probe'

  export default {
    props: {
      allSeller: {}
    },
    data() {
      return {}
    },
    created() {
      this.$nextTick(() => {
        this.initIscroll()
      })
    },
    computed: {
      ...mapGetters(["shopCart", "valueChange"]),
      total() {
        let price = 0
        if (this.shopCart) {
          this.shopCart.forEach((item) => {
            price += item.price * item.count
          })
        }
        return price
      },
      unmber() {
        let number = 0
        this.shopCart.forEach((item) => {
          number += item.count
        })
        return number
      },
      needmoney() {
        let minprice = this.allSeller.minPrice
        let aimprice = minprice - this.total
        return aimprice
      },
    },
    methods: {
      ...mapActions(['cleanCart']),
      initIscroll() {
        if(this.$refs.eachFoodList){
          this.foodsListScroll = new IScroll(this.$refs.eachFoodList, {
            click: true
          })
        }

      }
    },
    components: {
      Cartcontrol
    },
  }
</script>

<style lang="less" scoped>
  @import "../../common/less/mixin";

  .shopcart {
    position: fixed;
    height: 48px;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    z-index: 50;
    background: #141d27;
    .myfoodlist {
      position: absolute;
      bottom: 48px;
      width: 100%;
      max-height: 283px;
      overflow: auto;
      font-size: 12px;
      color: #ffff99;
      max-height: 180px;
      .cart-title {
        position: absolute;
        top: 0;
        padding: 0 18px;
        height: 40px;
        background: #f3f5f7;
        .border-1px(rgba(7, 17, 27, 0.4));
        h2 {
          font-size: 14px;
          font-weight: 200;
          line-height: 40px;
          color: black;
        }
        .clear {
          position: absolute;
          bottom: 0;
          right: 18px;
          font-size: 12px;
          color: rgb(0, 160, 220);
          line-height: 40px;
        }
      }
      .eachfood-list {
        background: #fff;
        overflow: hidden;
        &:last-child {
          .border-none
        }
        .eachfood {
          display: flex;
          padding: 12px 0;
          margin: 0 18px;
          .border-1px(rgba(7, 17, 27, 0.4));
          .food-name {
            flex: 1;
            font-size: 14px;
            line-height: 36px;
            color: black;
          }
          .food-price {
            flex: 0 0 30px;
            font-size: 14px;
            line-height: 36px;
            font-weight: 700;
            color: rgb(240, 20, 20);
            text-align: right;
            .yen {
              font-size: 10px;
              font-weight: normal;
            }
          }
          .ctrl {
            flex: 0 0 100px;
            padding-left: 20px;
            color: #000;
          }
          .button {
            margin-left: 20px;
          }
        }
      }
    }

    .footer-content {
      display: flex;
      font-size: 0;
      .content-left {
        flex: 1;
        .logo-warper, .price, .desc {
          display: inline-block;
        }
        .logo-warper {
          position: relative;
          top: -10px;
          z-index: 55;
          margin: 0 12px;
          padding: 6px;
          width: 44px;
          height: 44px;
          border-radius: 50%;
          vertical-align: top;
          background: #141d27;
          .logo {
            width: 100%;
            height: 100%;
            line-height: 44px;
            border-radius: 50%;
            text-align: center;
            font-size: 24px;
            background: #2B343C;
            color: rgba(255, 255, 255, 0.4);
            &.highlight {
              color: rgb(255, 255, 255);
              background: rgb(0, 160, 220);
            }
          }
          .num {
            position: absolute;
            top: 0;
            right: 0;
            width: 24px;
            height: 16px;
            line-height: 16px;
            text-align: center;
            border-radius: 8px;
            font-size: 9px;
            color: #fff;
            background: rgb(240, 20, 20);
            box-shadow: 0 4px 8px 0 rbga(0, 0, 0, 0.4);
          }
        }
        .price {
          margin: 12px 0;
          padding-right: 12px;
          border-right: 1px solid rgba(255, 255, 255, 0.1);
          line-height: 24px;
          font-size: 16px;
          font-weight: 700;
          color: rgba(255, 255, 255, 0.4);
          &.highlight {
            color: #fff;
          }
        }
        .desc {
          margin: 12px 0;
          padding-left: 12px;
          font-size: 10px;
          line-height: 24px;
          color: rgba(255, 255, 255, 0.4);
        }
      }
      .content-right {
        flex: 0 0 105px;
        width: 105px;
        background: #2B343C;
        .pay {
          padding: 0 8px;
          height: 48px;
          line-height: 48px;
          font-size: 12px;
          font-weight: 700;
          text-align: center;
          color: rgba(255, 255, 255, 0.4);
          &.enough {
            background: #55da6c;
            color: #fff;
          }
        }
      }
    }
  }
</style>
